'use strict';

import Base from './base.js';

export default class extends Base {
    /**
     * index action
     * @return {Promise} []
     */
    async indexAction() {
        return this.display();
    }

    async loginAction() {
        let user = await this.model("s_user").where({account: this.post("account")}).find();
        if (think.isEmpty(user) || user.password != think.md5(this.post("password"))) {
            this.fail("账号密码错误.")
        }
        this.session("user", user);
        this.success(user.name);
    }

    async logoutAction() {
        await this.session();
        return this.display('login');
    }

    async initAction() {
        let user = await this.session("user");
        this.success({
            userName: user.name
        });
    }

}